package com.gome.spiderkit.common;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class AppConfiguer {
	
	public static final String SINGLE_BLANK = " ";
	public static final String mongoIPKey = "MongoDBHost";
	public static final String mongoPortKey = "MongoDBPort";
	
	private static final String path = getConfDir() + "default.properties";
	
	public static String getConfDir() {
		return System.getProperty("user.dir") + "/../webapps/spiderkit-monitor/";
	}
	
	public static String getValueByKey(String key) {
		Properties pps = new Properties();
		InputStream in;
		try {
			in = new BufferedInputStream (new FileInputStream(path));
			pps.load(in);
			String value = pps.getProperty(key);
			in.close();
			return value;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
	public static String getStringByKey(String key) {
		return getValueByKey(key);
	}
	
	public static int getIntByKey(String key) {
		Properties pps = new Properties();
		InputStream in;
		try {
			in = new BufferedInputStream (new FileInputStream(path));
			pps.load(in);
			String value = pps.getProperty(key);
			in.close();
			return Integer.parseInt(value, 10);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}
	}
	
}
